Add CET-functionality to format-specific data.
authoroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 3 May 2006 23:37:38 +0000 (23:37 +0000)
committeroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 3 May 2006 23:37:38 +0000 (23:37 +0000)
gpsbabel/an1.c
gpsbabel/cet_util.c
gpsbabel/cet_util.h
gpsbabel/defs.h
gpsbabel/garmin_fs.c
gpsbabel/ozi.c
gpsbabel/xmltag.c

index c56806698577d1f6a8f63ff9b286889c5e7505ec..801de4d72cf8f18c4288542a229b078e5431ffa2 100644 (file)
@@ -314,6 +314,7 @@ static an1_waypoint_record *Alloc_AN1_Waypoint( ) {
        result->fs.type = FS_AN1W;
        result->fs.copy = Copy_AN1_Waypoint;
        result->fs.destroy = Destroy_AN1_Waypoint;
+       result->fs.convert = NULL;
        return result;
 }
        
@@ -336,6 +337,7 @@ static an1_vertex_record *Alloc_AN1_Vertex() {
        result->fs.type = FS_AN1V;
        result->fs.copy = Copy_AN1_Vertex;
        result->fs.destroy = Destroy_AN1_Vertex;
+       result->fs.convert = NULL;
        return result;
 }
                        
@@ -362,6 +364,7 @@ static an1_line_record *Alloc_AN1_Line( ) {
        result->fs.type = FS_AN1L;
        result->fs.copy = Copy_AN1_Line;
        result->fs.destroy = Destroy_AN1_Line;
+       result->fs.convert = NULL;
        return result;
 }
 
index 1a50afbc6ce1756abf57104c4144d2c2543c2828..08d021e545d684a3a85c21b1b41cd721ff2ecbc1 100644 (file)
@@ -947,6 +947,7 @@ static void
 cet_convert_waypt(const waypoint *wpt)
 {
        waypoint *w = (waypoint *)wpt;
+       format_specific_data *fs;
        
        if ((cet_output == 0) && (w->wpt_flags.cet_converted != 0)) return;
        
@@ -957,6 +958,14 @@ cet_convert_waypt(const waypoint *wpt)
        w->notes = cet_convert_string(wpt->notes);
        w->url = cet_convert_string(wpt->url);
        w->url_link_text = cet_convert_string(wpt->url_link_text);
+       
+       fs = wpt->fs;
+       while (fs != NULL)
+       {
+               if (fs->convert != NULL)
+                       fs->convert(fs);
+               fs = fs->next;
+       }
 }
 
 /* cet_convert_route_hdr: internal used within cet_convert_strings process */
@@ -993,8 +1002,6 @@ cet_convert_strings(const cet_cs_vec_t *source, const cet_cs_vec_t *target, cons
 {
        char *cs_name_from, *cs_name_to;
        
-//     printf("cet_convert_strings: enter\n"); fflush(stdout);
-       
        converter = NULL;
        
        if ((source == NULL) || (source == &cet_cs_vec_utf8))
@@ -1022,7 +1029,7 @@ cet_convert_strings(const cet_cs_vec_t *source, const cet_cs_vec_t *target, cons
        waypt_disp_all(cet_convert_waypt);
        route_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt);
        track_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt);
-
+       
        cet_output = 0;
        
        if (global_opts.debug_level > 0)
index b3ce840a8095b3b0f5f3c54694eb924cb57f3897..84754ca455520f5e8513317fb35ed210006293cd 100644 (file)
@@ -102,6 +102,9 @@ int cet_valid_char(const char *src, const cet_cs_vec_t *vec);
 int cet_vfprintf(FILE *stream, const cet_cs_vec_t *src_vec, const char *fmt, va_list args);
 int cet_fprintf(FILE *stream, const cet_cs_vec_t *src_vec, const char *fmt, ...);
 
+/* cet_convert_string: !!! ONLY VALID WITHIN 'cet_convert_strings' process !!! */
+char *cet_convert_string(char *str);
+
 /* gpsbabel extensions */
 
 void cet_convert_init(const char *cs_name, const int force);
index 170f3edf7ec8d00d1debf816169f374b60e289a1..9e0d0aed4c036478c8e7df945e2b976ef8adbcc8 100644 (file)
@@ -207,12 +207,15 @@ typedef struct xml_tag {
 
 typedef void (*fs_destroy)(void *);
 typedef void (*fs_copy)(void **, void *);
+typedef void (*fs_convert)(void *);
+
 typedef struct format_specific_data {
        long type;
        struct format_specific_data *next;
        
        fs_destroy destroy;
        fs_copy copy;
+       fs_convert convert;
 } format_specific_data;
 
 format_specific_data *fs_chain_copy( format_specific_data *source );
index 91858f3dfe53942192be5da13b9c31969b2d85a4..e409982bc5278d0bb14f5b41162a9d5c2024d93e 100644 (file)
@@ -36,6 +36,7 @@ garmin_fs_alloc(const int protocol)
        result->fs.type = FS_GMSD;
        result->fs.copy = (fs_copy) garmin_fs_copy;
        result->fs.destroy = garmin_fs_destroy;
+       result->fs.convert = NULL;
        result->fs.next = NULL;
        
        result->protocol = protocol;
index b72d44beb30c6e9367111512d12a08302a8dea52..985b34250d0430c52acf467d81f4349418b3ae92 100644 (file)
@@ -100,6 +100,7 @@ ozi_alloc_fsdata(void)
        fsdata->fs.type = FS_OZI;
        fsdata->fs.copy = (fs_copy) ozi_copy_fsdata;
        fsdata->fs.destroy = ozi_free_fsdata;
+       fsdata->fs.convert = NULL;
 
        /* Provide defaults via command line defaults */
        fsdata->fgcolor = color_to_bbggrr(wptfgcolor);
index 992ec4871aabbe95dd96fba29700572d49d6dfab..50c4a46ee5e26fc30be95d922929415e5b4bb2f7 100644 (file)
@@ -96,6 +96,25 @@ void copy_xml_tag( xml_tag **copy, xml_tag *src, xml_tag *parent ) {
        copy_xml_tag( &(res->child), src->child, res );
 }
 
+static void 
+convert_xml_tag( xml_tag *tag ) {
+       char **ap = NULL;
+       
+       if (tag == NULL) return;
+       
+       tag->cdata = cet_convert_string(tag->cdata);
+       tag->parentcdata = cet_convert_string(tag->parentcdata);
+       
+       ap = tag->attributes;
+       while (*ap)
+       {
+               *ap = cet_convert_string(*ap);
+               ap++;
+       }
+       convert_xml_tag(tag->sibling);
+       convert_xml_tag(tag->child);
+}
+
 fs_xml *fs_xml_alloc( long type );
 
 void fs_xml_destroy( void *fs ) {
@@ -117,6 +136,12 @@ void fs_xml_copy( void **copy, void *source ) {
        copy_xml_tag( &(((fs_xml *)(*copy))->tag), src->tag, NULL );
 }
 
+void fs_xml_convert( void *fs ) {
+       fs_xml *xml = (fs_xml *)fs;
+       if ( xml ) {
+               convert_xml_tag( xml->tag );
+       }
+}
 
 fs_xml *fs_xml_alloc( long type ) {
        fs_xml *result = NULL;
@@ -125,7 +150,7 @@ fs_xml *fs_xml_alloc( long type ) {
        result->fs.type = type;
        result->fs.copy = fs_xml_copy;
        result->fs.destroy = fs_xml_destroy;
+       result->fs.convert = fs_xml_convert;
        return result;
 }
 
-